package org.example.gobang.model;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {

    //往数据库里插入一个用户,用于注册功能
    @Insert("insert into user values (null, #{username}, #{password}, 1000, 0 , 0)")
    void insert(User user);
    //根据用户名查询用户信息,用于登录功能
    @Select("select * from user where username = #{usname}")
    User selectByName(String username);


    // 总比赛场数 + 1, 获胜场数 + 1, 天梯分数 + 30
    @Update("update user set totalCount = totalCount + 1, winCount = winCount + 1, score = score + 30\n" +
            "        where userId = #{userId}")
    void userWin(int userId);

    // 总比赛场数 + 1, 获胜场数 不变, 天梯分数 - 30
    @Update("update user set totalCount = totalCount + 1, score = score - 30\n" +
            "        where userId = #{userId}")
    void userLose(int userId);
}
